package com.BlackMesa.models;

import java.io.Serializable;
import java.util.ArrayList;
import android.graphics.Color;
/**
 * A grouping class for tasks; knows all the tasks that are assigned to this category.
 * @author Tyler Bishop, Nick Incardone
 * @version 1.1
 */
public class Category implements Serializable{
	private ArrayList<Task> tasks;
	private String name;
	private int color;
	private int id;
	private int userid;
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets up a category with no tasks and a set color and name.
	 * @param name
	 * 		name of the category
	 * @param color
	 * 		color the category is assigned
	 */
	public Category(String name, int color) {
		this.color = color;
		this.name = name;
		tasks = new ArrayList<Task>();
	}
	
	/**
	 * Adds the given task to this category.
	 * @param t
	 * 		task to be added
	 */
	public void addTask(Task t,boolean oldPermCat) {
		if(t==null){
			return;
		}
		if(!this.equals(t.getCategory())) {
			if(!oldPermCat) {
				if(t.getCategory() != null) {
					t.getCategory().removeTask(t);
				}
				t.setCategory(this);
			}
		}
		if(!containsTask(t)) {
			tasks.add(t);
		}
	}
	
	/**
	 * 
	 * @param t
	 */
	public void addTaskForDate(Task t) {
		tasks.add(t);
	}
	
	/**
	 * 
	 * @param t
	 * @return
	 */
	public boolean containsTask(Task t) {
		for(Task myTask:tasks) {
			if(t.equals(myTask)) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Removes the given task from this category.
	 * @param t
	 * 		task to be removed
	 */
	public void removeTask(Task t) {
		tasks.remove(t);
	}

	/**
	 * 
	 * @return
	 */
	public ArrayList<Task> getTasks() {
		return tasks;
	}

	/**
	 * 
	 * @param tasks
	 */
	public void setTasks(ArrayList<Task> tasks) {
		this.tasks = tasks;
	}

	/**
	 * 
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * 
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 
	 * @return
	 */
	public int getColor() {
		return color;
	}

	/**
	 * 
	 * @param color
	 */
	public void setColor(int color) {
		this.color = color;
	}
	
	/**
	 * 
	 * @param that
	 * @return
	 */
	public boolean equals(Object that) {
		if(that == null) {
			return false;
		}
		if(that.getClass() != Category.class) {
			return false;
		}
		return this.name.equals(((Category)that).name);
	}

	/**
	 * @param string
	 * @return
	 */
	public static Color str2Color(String string) {
		// TODO Auto-generated method stub
		return null;
	}

	public int getUserid() {
		return userid;
	}

	public void setUserid(int userid) {
		this.userid = userid;
	}

}
